package ooday04.homework2;


import ooday04.Swim;

//创建Animal数组并填充Dog/Chick/Fish对象，遍历数组：
//     - 输出每个动物的名字，让每个动物吃饭、喝水
//     - 若为Dog，则让它看家。若为Chick，则让它下蛋。若能游泳，则让它游泳。
public class Test {
    public static void main(String[] args) {
        Animal[] animals = new Animal[5];
        animals[0] = new Dog("小黑", 2, "黑");
        animals[1] = new Dog("小白", 1, "白");
        animals[2] = new Dog("小灰", 3, "灰");
        animals[3] = new Dog("小金", 2, "金");
        animals[4] = new Dog("小花", 3, "黑");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].drink();
            animals[i].eat();

            if (animals[i] instanceof Dog) {
                Dog dog = (Dog) animals[i];
                dog.lookHome();
            }

            if (animals[i] instanceof Swim) {
                Swim s = (Swim) animals[i];
                s.swim();
            }

        }

    }
}